﻿Imports MySql.Data.MySqlClient

Public Class CLINIC
    Dim connect As CONDB = CONDB.NewConnection()
    Dim s As FILTERCLASS
    Dim PROVIDER_MASCLINIC As New PROVIDERSCLASS

    Public Sub New()

        ' This call is required by the designer.
        InitializeComponent()
        SelectDatagridMasclinic()
        ' Add any initialization after the InitializeComponent() call.

    End Sub
    Private Sub SearchCoperate()
        Dim sql2 As String
        sql2 = "SELECT `coperateid`,`coperatename`,`code` FROM masclsoperate WHERE `status` = 1 "
        s = New FILTERCLASS(txtCoperateid, sql2, "ID หมวดหัตถการ,ชื่อหมวดหัตถการ,รหัสหมวดหัตถการ", "100,120,70", "0,1,1", "0,1,1")
        s.SetTagIndex = 0 ' settag
        s.SetTextIndex = 1 'settext
        s.SetShowBorder = True
    End Sub

    Private Sub filterStock()
        Dim sql2 As String
        sql2 = "SELECT CAST(`stkid` AS CHAR(8)) AS 'id', `stkname`, `location`, `f_sale`, `f_drug`, `f_medsup`, `f_supply` FROM stock WHERE `status` = 1"
        s = New FILTERCLASS(txtStkid, sql2, "id,ชื่อคลัง,ที่ตั้งคลัง,ขาย,ยา,เวชภัณฑ์,พัสดุ", "40,120,120,40,40,60,40", "1,1,1,1,1,1,1", "0,1,1,0,0,0,0")
        s.SetTagIndex = 0 ' settag
        s.SetTextIndex = 1 'settext
        s.SetShowBorder = True
    End Sub

    Private Sub filterRx()
        Dim sql2 As String
        sql2 = "SELECT CAST(`clinic` AS CHAR(8)) AS 'id', `cliniccode`, `clinicname` FROM masclinic WHERE `status` = 1"
        s = New FILTERCLASS(txtPhx, sql2, "id,code,ชื่อคลินิก", "40,80,120", "1,1,1", "0,1,1")
        s.SetTagIndex = 0 ' settag
        s.SetTextIndex = 2 'settext
        s.SetShowBorder = True
    End Sub

    Private Sub filterFinance()
        Dim sql2 As String
        sql2 = "SELECT CAST(`clinic` AS CHAR(8)) AS 'id', `cliniccode`, `clinicname` FROM masclinic WHERE `status` = 1"
        s = New FILTERCLASS(txtCash, sql2, "id,code,ชื่อคลินิก", "40,80,120", "1,1,1", "0,1,1")
        s.SetTagIndex = 0 ' settag
        s.SetTextIndex = 2 'settext
        s.SetShowBorder = True
    End Sub

    Private Sub filterDr()
        Dim sql2 As String
        sql2 = "SELECT CAST(`clinic` AS CHAR(8)) AS 'id', `cliniccode`, `clinicname` FROM masclinic WHERE `status` = 1"
        s = New FILTERCLASS(txtDr, sql2, "id,code,ชื่อคลินิก", "40,80,120", "1,1,1", "0,1,1")
        s.SetTagIndex = 0 ' settag
        s.SetTextIndex = 2 'settext
        s.SetShowBorder = True
    End Sub

    Private Sub filterDc()
        Dim sql2 As String
        sql2 = "SELECT CAST(`clinic` AS CHAR(8)) AS 'id', `cliniccode`, `clinicname` FROM masclinic WHERE `status` = 1"
        s = New FILTERCLASS(txtDc, sql2, "id,code,ชื่อคลินิก", "40,80,120", "1,1,1", "0,1,1")
        s.SetTagIndex = 0 ' settag
        s.SetTextIndex = 2 'settext
        s.SetShowBorder = True
    End Sub

    Private Sub filterXray()
        Dim sql2 As String
        sql2 = "SELECT CAST(`clinic` AS CHAR(8)) AS 'id', `cliniccode`, `clinicname` FROM masclinic WHERE `status` = 1"
        s = New FILTERCLASS(txtXry, sql2, "id,code,ชื่อคลินิก", "40,80,120", "1,1,1", "0,1,1")
        s.SetTagIndex = 0 ' settag
        s.SetTextIndex = 2 'settext
        s.SetShowBorder = True
        s.SetShowInDown = False
    End Sub

    Private Sub filterLab()
        Dim sql2 As String
        sql2 = "SELECT CAST(`clinic` AS CHAR(8)) AS 'id', `cliniccode`, `clinicname` FROM masclinic WHERE `status` = 1"
        s = New FILTERCLASS(txtLab, sql2, "id,code,ชื่อคลินิก", "40,80,120", "1,1,1", "0,1,1")
        s.SetTagIndex = 0 ' settag
        s.SetTextIndex = 2 'settext
        s.SetShowBorder = True
        s.SetShowInDown = False
    End Sub

    Private Sub CLINIC_Load(sender As Object, e As EventArgs) Handles Me.Load
        SearchCoperate()
        filterStock()
        filterRx()
        filterFinance()
        filterDr()
        filterDc()
        filterXray()
        filterLab()

        'SelectDatagridMasclinic()

        DesignForm(Me)
        DesignGrid(dgvMasclinic)

        PROVIDER_MASCLINIC.GETHOSEM(CInt(main.txtUserRequest.Text.Trim), Convert.ToString(Me.Tag))
    End Sub
    Private Sub SelectDatagridMasclinic()
        'connect.Dispose()
        connect = CONDB.NewConnection
        Dim objSelectDataMasclinic As New MASCLINIC
        'Dim CLINIC As DataTable
        Dim mysqlReader As MySqlDataReader
        mysqlReader = connect.ExecuteReader(objSelectDataMasclinic.selectMasClinic_)
        dgvMasclinic.Rows.Clear()
        While mysqlReader.Read
            'dgvMasclinic.Rows.Add({mysqlReader("COLOR"), mysqlReader("รหัสหน่วยงาน"), mysqlReader("ชื่อย่อหน่วยงาน"), mysqlReader("ชื่อหน่วยงาน"), mysqlReader("clinicname_en"), mysqlReader("FMEDdgv"), mysqlReader("F_SEQdgv"), mysqlReader("F_WRDdgv"), mysqlReader("COPERATEID"), mysqlReader("หมวดหัตถการ"), mysqlReader("เบอร์โทร"), mysqlReader("สถานะการเปิดใช้งาน")})
            dgvMasclinic.Rows.Add({mysqlReader("COLOR"), mysqlReader("รหัสหน่วยงาน"), mysqlReader("ชื่อย่อหน่วยงาน"), mysqlReader("ชื่อหน่วยงาน"), mysqlReader("clinicname_en"), mysqlReader("เบอร์โทร"), mysqlReader("coperateid"), mysqlReader("หมวดหัตถการ"), mysqlReader("รหัสคลัง"), mysqlReader("คลัง"), mysqlReader("รหัสคลินิกยาที่ส่งต่อ"), mysqlReader("คลินิกยาที่ส่งต่อ"), mysqlReader("รหัสแผนกการเงินที่ส่งต่อ"), mysqlReader("แผนกการเงินที่ส่งต่อ"), mysqlReader("รหัสห้องตรวจที่ส่งต่อ"), mysqlReader("ชื่อห้องตรวจที่ส่งต่อ"), mysqlReader("รหัสแผนกส่งต่ออัตโนมัติ"), mysqlReader("แผนกที่ส่งต่อโดยอัตโนมัติ"), mysqlReader("รหัสแผนกxrayที่ส่งต่อ"), mysqlReader("ชื่อแผนกxrayที่ส่งต่อ"), mysqlReader("รหัสแผนกlabที่ส่งต่อ"), mysqlReader("ชื่อแผนกlabที่ส่งต่อ"), mysqlReader("fmeddgv"), mysqlReader("F_SEQdgv"), mysqlReader("F_WRDdgv"), mysqlReader("F_EXMdgv"), mysqlReader("สถานะการเปิดใช้งาน")})
            'DataGridViewX2.Rows.Add({mysqlReader("CLINIC")})
            'DataGridViewX2.Rows.Add({mysqlReader("CLINIC")})
        End While
        For i As Integer = 0 To dgvMasclinic.Rows.Count - 1
            Dim colorx() As String
            If dgvMasclinic.Rows(i).Cells("COLOR").Value IsNot Nothing Then
                If dgvMasclinic.Rows(i).Cells("COLOR").Value.ToString.Trim <> "" Then
                    colorx = dgvMasclinic.Rows(i).Cells("COLOR").Value.ToString.Trim.Split(",")
                    dgvMasclinic.Rows(i).Cells("ชื่อย่อหน่วยงาน").Style.BackColor = System.Drawing.Color.FromArgb(CInt(colorx(0)), CInt(colorx(1)), CInt(colorx(2)))

                End If
            End If
        Next
        '    If dgvClinic.Rows(i).Cells("COLOR").Value.ToString.Trim <> "" Then

        '    End I
        'Next i
    End Sub



    'Private Sub MASCLINICGrid_CellClick(sender As Object, e As DevComponents.DotNetBar.SuperGrid.GridCellClickEventArgs) Handles MASCLINICGrid.CellClick
    '    Dim grid As DevComponents.DotNetBar.SuperGrid.GridRow
    '    grid = e.GridPanel.ActiveRow
    '    If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสหน่วยงาน").Value() IsNot DBNull.Value Then
    '        CLINICTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสหน่วยงาน").Value()
    '    Else
    '        CLINICTxt.Text = ""
    '    End If
    '    If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ชื่อย่อหน่วยงาน").Value() IsNot DBNull.Value Then
    '        CLINICCODETxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ชื่อย่อหน่วยงาน").Value()
    '    Else
    '        CLINICCODETxt.Text = ""
    '    End If
    '    If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ชื่อหน่วยงาน").Value() IsNot DBNull.Value Then
    '        CLINICNAMETxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ชื่อหน่วยงาน").Value()
    '    Else
    '        CLINICNAMETxt.Text = ""
    '    End If
    '    If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("FMED").Value() = True Then
    '        FMED.Checked = True
    '    Else
    '        FMED.Checked = False
    '    End If
    '    If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("F_SEQ").Value() = True Then
    '        F_SEQ.Checked = True
    '    Else
    '        F_SEQ.Checked = False
    '    End If
    '    If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("F_WRD").Value() = True Then
    '        F_WRD.Checked = True
    '    Else
    '        F_WRD.Checked = False
    '    End If
    '    If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value() = True Then
    '        masclinicStatusCheckbox.Checked = True
    '    Else
    '        masclinicStatusCheckbox.Checked = False
    '    End If
    '    connect = CONDB.NewConnection()
    '    If e.GridCell.GridColumn.Name = "สถานะการเปิดใช้งาน" Then
    '        Try
    '            Dim Sql As String
    '            connect.BeginTrans()
    '            Sql = "UPDATE MASCLINIC SET "
    '            If Convert.ToBoolean(CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value()) = True Then
    '                Sql += "`STATUS` = 1 "
    '            Else
    '                Sql += "`STATUS` = 0 "
    '            End If
    '            Sql += "WHERE `CLINIC` = '" & CLINICTxt.Text & "' ;"
    '            connect.ExecuteNonQuery(Sql)
    '            connect.CommitTrans()
    '        Catch ex As Exception
    '            connect.RollbackTrans()
    '            MsgBox(ex.ToString)
    '        End Try
    '    End If
    '    connect.Dispose()
    '    'connectlocal = conlocal.NewConnection()
    '    'If e.GridCell.GridColumn.Name = "สถานะการเปิดใช้งาน" Then
    '    '    Try
    '    '        Dim Sql As String
    '    '        connectlocal.BeginTrans()
    '    '        Sql = "UPDATE MASRELIGION SET "
    '    '        If Convert.ToBoolean(CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value()) = True Then
    '    '            Sql += "[STATUS] = 1 "
    '    '        Else
    '    '            Sql += "[STATUS] = 0 "
    '    '        End If
    '    '        Sql += "WHERE [RELIGION] = '" & RELIGIONIDTxt.Text & "' ;"

    '    '        connectlocal.ExecuteNonQuery(Sql)
    '    '        connectlocal.CommitTrans()
    '    '    Catch ex As Exception
    '    '        connectlocal.RollbackTrans()
    '    '        MsgBox(ex.ToString)
    '    '    End Try
    '    'End If
    '    'connectlocal.Dispose()
    '    addMasclinic.Enabled = False
    'End Sub

    Private Sub COPERATENAMETxt_Click(sender As Object, e As EventArgs) Handles txtCoperateid.Click
        txtCoperateid.Text = ""
    End Sub

    Private Sub CLINICTxt_KeyPress(sender As Object, e As KeyPressEventArgs)
        If txtClinic.Text.Length > 2 And Not Char.IsControl(e.KeyChar) Then
            e.KeyChar = ""
        End If
    End Sub

    Private Sub CLINICCODETxt_KeyPress(sender As Object, e As KeyPressEventArgs)
        If txtCliniccode.Text.Length > 4 And Not Char.IsControl(e.KeyChar) Then
            e.KeyChar = ""
        End If
    End Sub

    Private Sub TELTxt_KeyPress(sender As Object, e As KeyPressEventArgs)
        If txtTel.Text.Length > 9 And Not Char.IsControl(e.KeyChar) Then
            e.KeyChar = ""
        End If
    End Sub

    'Private Sub DataGridViewX2_CellMouseClick(sender As Object, e As DataGridViewCellMouseEventArgs)
    '    If e.RowIndex < 0 Then
    '        Return
    '    End If
    '    CLINICTxt.Text = DataGridViewX2.Rows(e.RowIndex).Cells("รหัสหน่วยงาน").Value.ToString
    '    CLINICCODETxt.Text = DataGridViewX2.Rows(e.RowIndex).Cells("ชื่อย่อหน่วยงาน").Value.ToString
    '    CLINICNAMETxt.Text = DataGridViewX2.Rows(e.RowIndex).Cells("ชื่อหน่วยงาน").Value.ToString
    '    Dim colorx() As String
    '    If DataGridViewX2.Rows(e.RowIndex).Cells("COLOR").Value.ToString.Trim <> "" Then
    '        colorx = DataGridViewX2.Rows(e.RowIndex).Cells("COLOR").Value.ToString.Trim.Split(",")
    '        ColorPickerButton1.SelectedColor = System.Drawing.Color.FromArgb(colorx(0), colorx(1), colorx(2))
    '    Else
    '        ColorPickerButton1.SelectedColor = Nothing
    '    End If
    '    FMED.Checked = DataGridViewX2.Rows(e.RowIndex).Cells("FMEDdgv").Value.ToString
    '    F_SEQ.Checked = DataGridViewX2.Rows(e.RowIndex).Cells("F_SEQdgv").Value.ToString
    '    F_WRD.Checked = DataGridViewX2.Rows(e.RowIndex).Cells("F_WRDdgv").Value.ToString
    '    COPERATENAMETxt.Tag = DataGridViewX2.Rows(e.RowIndex).Cells("COPERATEID").Value.ToString
    '    COPERATENAMETxt.Text = DataGridViewX2.Rows(e.RowIndex).Cells("หมวดหัตถการ").Value.ToString
    '    TELTxt.Text = DataGridViewX2.Rows(e.RowIndex).Cells("เบอร์โทร").Value.ToString
    '    masclinicStatusCheckbox.Checked = DataGridViewX2.Rows(e.RowIndex).Cells("สถานะการเปิดใช้งาน").Value.ToString
    '    addMasclinic.Enabled = False
    'End Sub

    Private Sub DataGridViewX2_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvMasclinic.CellClick
        If e.RowIndex < 0 Then
            Return
        End If
        txtClinic.Text = dgvMasclinic.Rows(e.RowIndex).Cells("รหัสหน่วยงาน").Value.ToString
        txtCliniccode.Text = dgvMasclinic.Rows(e.RowIndex).Cells("ชื่อย่อหน่วยงาน").Value.ToString
        txtClinicname.Text = dgvMasclinic.Rows(e.RowIndex).Cells("ชื่อหน่วยงาน").Value.ToString
        txtClinicname_en.Text = dgvMasclinic.Rows(e.RowIndex).Cells("clinicname_en").Value.ToString
        txtTel.Text = dgvMasclinic.Rows(e.RowIndex).Cells("เบอร์โทร").Value.ToString

        Dim colorx() As String
        If dgvMasclinic.Rows(e.RowIndex).Cells("COLOR").Value.ToString.Trim <> "" Then
            colorx = dgvMasclinic.Rows(e.RowIndex).Cells("COLOR").Value.ToString.Trim.Split(",")
            ColorPickerButton1.SelectedColor = System.Drawing.Color.FromArgb(colorx(0), colorx(1), colorx(2))
        Else
            ColorPickerButton1.SelectedColor = Nothing
        End If

        txtCoperateid.Tag = dgvMasclinic.Rows(e.RowIndex).Cells("coperateid").Value.ToString
        txtCoperateid.Text = dgvMasclinic.Rows(e.RowIndex).Cells("หมวดหัตถการ").Value.ToString

        txtStkid.Tag = dgvMasclinic.Rows(e.RowIndex).Cells("รหัสคลัง").Value.ToString
        txtStkid.Text = dgvMasclinic.Rows(e.RowIndex).Cells("คลัง").Value.ToString

        txtPhx.Tag = dgvMasclinic.Rows(e.RowIndex).Cells("รหัสคลินิกยาที่ส่งต่อ").Value.ToString
        txtPhx.Text = dgvMasclinic.Rows(e.RowIndex).Cells("คลินิกยาที่ส่งต่อ").Value.ToString

        txtCash.Tag = dgvMasclinic.Rows(e.RowIndex).Cells("รหัสแผนกการเงินที่ส่งต่อ").Value.ToString
        txtCash.Text = dgvMasclinic.Rows(e.RowIndex).Cells("แผนกการเงินที่ส่งต่อ").Value.ToString

        txtDr.Tag = dgvMasclinic.Rows(e.RowIndex).Cells("รหัสห้องตรวจที่ส่งต่อ").Value.ToString
        txtDr.Text = dgvMasclinic.Rows(e.RowIndex).Cells("ชื่อห้องตรวจที่ส่งต่อ").Value.ToString

        txtDc.Tag = dgvMasclinic.Rows(e.RowIndex).Cells("รหัสแผนกส่งต่ออัตโนมัติ").Value.ToString
        txtDc.Text = dgvMasclinic.Rows(e.RowIndex).Cells("แผนกที่ส่งต่อโดยอัตโนมัติ").Value.ToString

        txtXry.Tag = dgvMasclinic.Rows(e.RowIndex).Cells("รหัสแผนกxrayที่ส่งต่อ").Value.ToString
        txtXry.Text = dgvMasclinic.Rows(e.RowIndex).Cells("ชื่อแผนกxrayที่ส่งต่อ").Value.ToString

        txtLab.Tag = dgvMasclinic.Rows(e.RowIndex).Cells("รหัสแผนกlabที่ส่งต่อ").Value.ToString
        txtLab.Text = dgvMasclinic.Rows(e.RowIndex).Cells("ชื่อแผนกlabที่ส่งต่อ").Value.ToString

        ckbFmed.Checked = dgvMasclinic.Rows(e.RowIndex).Cells("FMEDdgv").Value.ToString
        ckbF_seq.Checked = dgvMasclinic.Rows(e.RowIndex).Cells("F_SEQdgv").Value.ToString
        ckbF_wrd.Checked = dgvMasclinic.Rows(e.RowIndex).Cells("F_WRDdgv").Value.ToString
        ckbF_exm.Checked = dgvMasclinic.Rows(e.RowIndex).Cells("F_EXMdgv").Value.ToString

        ckbStatus.Checked = dgvMasclinic.Rows(e.RowIndex).Cells("สถานะการเปิดใช้งาน").Value.ToString
        addMasclinic.Enabled = False
    End Sub

    Private Sub addMasclinic_Click_1(sender As Object, e As EventArgs) Handles addMasclinic.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_MASCLINIC.PADD_ = True Then
                If txtCliniccode.Text.ToString.Length > 0 Then
                    Dim objInsertData As New MASCLINIC
                    objInsertData.CLINICCODE_ = txtCliniccode.Text
                    objInsertData.CLINICNAME_ = txtClinicname.Text.Trim
                    objInsertData.CLINICNAME_EN_ = txtClinicname_en.Text.Trim
                    objInsertData.TEL_ = txtTel.Text

                    If ColorPickerButton1.SelectedColor.R <> 0 And ColorPickerButton1.SelectedColor.G <> 0 And ColorPickerButton1.SelectedColor.B <> 0 Then
                        objInsertData.COLOR_ = ColorPickerButton1.SelectedColor.R.ToString + "," + ColorPickerButton1.SelectedColor.G.ToString + "," + ColorPickerButton1.SelectedColor.B.ToString
                    End If

                    If Convert.ToString(txtCoperateid.Tag).Trim <> "" Then
                        objInsertData.COPERATEID_ = Convert.ToString(txtCoperateid.Tag).Trim
                    End If

                    If Convert.ToString(txtStkid.Tag).Trim <> "" Then
                        objInsertData.STKID_ = Convert.ToString(txtStkid.Tag).Trim
                    End If

                    If Convert.ToString(txtPhx.Tag).Trim <> "" Then
                        objInsertData.PHX_ = Convert.ToString(txtPhx.Tag).Trim
                    End If

                    If Convert.ToString(txtCash.Tag).Trim <> "" Then
                        objInsertData.CASH_ = Convert.ToString(txtCash.Tag).Trim
                    End If

                    If Convert.ToString(txtDr.Tag).Trim <> "" Then
                        objInsertData.DR_ = Convert.ToString(txtDr.Tag).Trim
                    End If

                    If Convert.ToString(txtDc.Tag).Trim <> "" Then
                        objInsertData.DC_ = Convert.ToString(txtDc.Tag).Trim
                    End If

                    If Convert.ToString(txtXry.Tag).Trim <> "" Then
                        objInsertData.XRY_ = Convert.ToString(txtXry.Tag).Trim
                    End If

                    If Convert.ToString(txtLab.Tag).Trim <> "" Then
                        objInsertData.LAB_ = Convert.ToString(txtLab.Tag).Trim
                    End If

                    objInsertData.FMED_ = ckbFmed.Checked
                    objInsertData.F_SEQ_ = ckbF_seq.Checked
                    objInsertData.F_WRD_ = ckbF_wrd.Checked
                    objInsertData.F_EXM_ = ckbF_exm.Checked
                    objInsertData.ClinicStatus_ = ckbStatus.Checked

                    If objInsertData.insertMasClinicData() = True Then
                        SelectDatagridMasclinic()
                        cleardata()
                    End If
                Else
                    MsgBox("โปรดระบุข้อมูลให้ครบถ้วน", MsgBoxStyle.Critical)
                End If
            Else
                MsgBox(PROVIDER_MASCLINIC.PADDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub editMasclinic_Click_1(sender As Object, e As EventArgs) Handles editMasclinic.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_MASCLINIC.PUPD_ = True Then
                If txtClinicname.Text.Length > 0 Then
                    Dim editStat As Integer
                    editStat = MsgBox("ท่านต้องการแก้ไขข้อมูลดังกล่าวใช่หรือไม่", MsgBoxStyle.OkCancel)
                    If editStat = 1 Then
                        Dim objEditData As New MASCLINIC
                        objEditData.CLINIC_ = txtClinic.Text
                        objEditData.CLINICCODE_ = txtCliniccode.Text
                        objEditData.CLINICNAME_ = txtClinicname.Text.Trim
                        objEditData.CLINICNAME_EN_ = txtClinicname_en.Text.Trim
                        objEditData.TEL_ = txtTel.Text

                        If ColorPickerButton1.SelectedColor.R <> 0 And ColorPickerButton1.SelectedColor.G <> 0 And ColorPickerButton1.SelectedColor.B <> 0 Then
                            objEditData.COLOR_ = ColorPickerButton1.SelectedColor.R.ToString + "," + ColorPickerButton1.SelectedColor.G.ToString + "," + ColorPickerButton1.SelectedColor.B.ToString
                        End If

                        If Convert.ToString(txtCoperateid.Tag).Trim <> "" Then
                            objEditData.COPERATEID_ = Convert.ToString(txtCoperateid.Tag).Trim
                        End If

                        If Convert.ToString(txtStkid.Tag).Trim <> "" Then
                            objEditData.STKID_ = Convert.ToString(txtStkid.Tag).Trim
                        End If

                        If Convert.ToString(txtPhx.Tag).Trim <> "" Then
                            objEditData.PHX_ = Convert.ToString(txtPhx.Tag).Trim
                        End If

                        If Convert.ToString(txtCash.Tag).Trim <> "" Then
                            objEditData.CASH_ = Convert.ToString(txtCash.Tag).Trim
                        End If

                        If Convert.ToString(txtDr.Tag).Trim <> "" Then
                            objEditData.DR_ = Convert.ToString(txtDr.Tag).Trim
                        End If

                        If Convert.ToString(txtDc.Tag).Trim <> "" Then
                            objEditData.DC_ = Convert.ToString(txtDc.Tag).Trim
                        End If

                        If Convert.ToString(txtXry.Tag).Trim <> "" Then
                            objEditData.XRY_ = Convert.ToString(txtXry.Tag).Trim
                        End If

                        If Convert.ToString(txtLab.Tag).Trim <> "" Then
                            objEditData.LAB_ = Convert.ToString(txtLab.Tag).Trim
                        End If

                        objEditData.FMED_ = ckbFmed.Checked
                        objEditData.F_SEQ_ = ckbF_seq.Checked
                        objEditData.F_WRD_ = ckbF_wrd.Checked
                        objEditData.F_EXM_ = ckbF_exm.Checked
                        objEditData.ClinicStatus_ = ckbStatus.Checked

                        If objEditData.editMasClinicData() = True Then
                            SelectDatagridMasclinic()
                            cleardata()
                        End If
                    End If
                Else
                    MsgBox("โปรดระบุข้อมูลให้ครบถ้วน", MsgBoxStyle.Critical)
                End If

                addMasclinic.Enabled = True
            Else
                MsgBox(PROVIDER_MASCLINIC.PUPDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub importExel_Click(sender As Object, e As EventArgs) Handles importExel.Click
        Dim nextform As New IMPORTEXCEL(masclinic.Text)
        nextform.ShowDialog()
    End Sub

    Private Sub ButtonItem1_Click(sender As Object, e As EventArgs) Handles ButtonItem1.Click
        Dim nextform As New IMPORTEXCEL(masclinic.Text)
        nextform.ShowDialog()
    End Sub


    Private Sub btnClearForm_Click(sender As Object, e As EventArgs) Handles btnClearForm.Click
        cleardata()
        addMasclinic.Enabled = True
    End Sub

    Private Sub cleardata()
        txtClinic.Clear()
        txtCliniccode.Clear()
        txtClinicname.Clear()
        txtClinicname_en.Clear()
        txtTel.Clear()
        ColorPickerButton1.SelectedColor = Nothing

        txtCoperateid.Tag = ""
        txtCoperateid.Clear()
        txtStkid.Tag = ""
        txtStkid.Clear()
        txtPhx.Tag = ""
        txtPhx.Clear()
        txtCash.Tag = ""
        txtCash.Clear()
        txtDr.Tag = ""
        txtDr.Clear()
        txtDc.Tag = ""
        txtDc.Clear()
        txtXry.Tag = ""
        txtXry.Clear()
        txtLab.Tag = ""
        txtLab.Clear()

        ckbFmed.Checked = False
        ckbF_seq.Checked = False
        ckbF_wrd.Checked = False
        ckbF_exm.Checked = False
        ckbStatus.Checked = False
    End Sub
End Class